package com.kexio.pay.enums;

/**
 * 支付场景枚举
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public enum PaymentScene {
    
    /**
     * PC网站支付
     */
    PC("PC", "PC网站支付"),
    
    /**
     * 手机网站支付
     */
    WAP("WAP", "手机网站支付"),
    
    /**
     * APP支付
     */
    APP("APP", "APP支付"),
    
    /**
     * 小程序支付
     */
    MINI_PROGRAM("MINI_PROGRAM", "小程序支付"),
    
    /**
     * 扫码支付
     */
    QR_CODE("QR_CODE", "扫码支付"),
    
    /**
     * 刷卡支付 (线下)
     */
    POS("POS", "刷卡支付"),
    
    /**
     * 条码支付 (用户扫商家码)
     */
    BARCODE("BARCODE", "条码支付"),
    
    /**
     * API支付 (服务端)
     */
    API("API", "API支付");
    
    private final String code;
    private final String description;
    
    PaymentScene(String code, String description) {
        this.code = code;
        this.description = description;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 根据代码获取枚举
     */
    public static PaymentScene fromCode(String code) {
        for (PaymentScene scene : values()) {
            if (scene.getCode().equals(code)) {
                return scene;
            }
        }
        throw new IllegalArgumentException("Unknown payment scene code: " + code);
    }
    
    /**
     * 是否为移动端场景
     */
    public boolean isMobile() {
        return this == WAP || this == APP || this == MINI_PROGRAM;
    }
    
    /**
     * 是否为线上场景
     */
    public boolean isOnline() {
        return this != POS && this != BARCODE;
    }
    
    /**
     * 是否需要用户交互
     */
    public boolean needUserInteraction() {
        return this != API && this != BARCODE;
    }
}
